public class Main {
    public static void main(String[] args) {

        System.out.println(sum(123));
    }

    public static int sum(int n){
        if(n == 0){
            return 0;
        }
        return  (n % 10) + sum(n / 10);
    }
}


////力扣236二叉树最近公共祖先
//class Solution {
//    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
//        if(root == null){
//            return null;
//        }
//        if(root == p || root == q){
//            return root;
//        }
//        TreeNode retLeft = lowestCommonAncestor(root.left,p,q);
//        TreeNode retRight = lowestCommonAncestor(root.right,p,q);
//        if(retLeft != null && retRight != null){
//            return root;
//        }else if(retRight == null){
//            return retLeft;
//        }else{
//            return retRight;
//        }
//    }
//}